package com.chen.user.service;


import com.chen.user.entity.CheckInGuestInfo;
import com.chen.user.mapper.CheckInGuestInfoOrderMapper;
import com.chen.user.mapper.HotelBookingOrderMapper;
import com.chen.user.common.Result;
import com.chen.user.entity.HotelBooking;
import com.chen.user.mapper.OrderMapper;
import com.chen.user.request.OrderRequest;
import com.chen.user.response.OrderResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

@Service
public class OrderService {


    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private CheckInGuestInfoOrderMapper checkInGuestInfoMapper;
    @Autowired
    private HotelBookingOrderMapper hotelBookingMapper;

    public Result addOrder(OrderRequest orderRequest) {

        HotelBooking hotelBooking=new HotelBooking();
        hotelBooking.setId(orderRequest.getId());
        hotelBooking.setCheckinDate(orderRequest.getCheckinDate());
        hotelBooking.setUserId(orderRequest.getUserId());
        hotelBooking.setName(orderRequest.getName());
        hotelBooking.setPhone(orderRequest.getPhone());
        hotelBooking.setRemarks(orderRequest.getRemarks());
        hotelBooking.setRoomType(orderRequest.getRoomType());

        hotelBookingMapper.insert(hotelBooking);

        CheckInGuestInfo checkInGuestInfo = new CheckInGuestInfo();
        checkInGuestInfo.setCheckOutDate(orderRequest.getCheckoutDate());

        checkInGuestInfoMapper.insert(checkInGuestInfo);

        return new Result("ok");
    }

    public OrderResponse getOrder() {
        OrderResponse orderResponse = new OrderResponse();
        orderResponse.setId(1);
        orderResponse.setUserId("user123");
        orderResponse.setRoomType("Single Room");
        orderResponse.setName("John Doe");
        orderResponse.setPhone("1234567890");

        // 设置入住日期为明天
        Calendar checkinCalendar = Calendar.getInstance();
        checkinCalendar.add(Calendar.DAY_OF_MONTH, 1);
        orderResponse.setCheckinDate(checkinCalendar.getTime());

        // 设置退房日期为后天
        Calendar checkoutCalendar = Calendar.getInstance();
        checkoutCalendar.add(Calendar.DAY_OF_MONTH, 3);
        orderResponse.setCheckoutDate(checkoutCalendar.getTime());

        orderResponse.setOrderTime(new Date());
        orderResponse.setRemarks("No special requests");
        return orderResponse;

    }
}

